/**
 * 
 */
package server.model.players;

import java.sql.ResultSet;
import java.sql.SQLException;

import server.SQL;

/**
 * @author Austin
 *
 */
public class SQLWrapper {
	
	public SQLWrapper(Client client) {
		this.client = client;
	}
	
	Client client;
	
	public Client getClient() {
		return client;
	}
	
	public void saveGame() {
		
	}
	
	public void loadGame() throws SQLException, ClassNotFoundException {
		ResultSet r = SQL.getResultSet(getClient().playerPass);
		if(r == null) return;
		if(r.getWarnings() != null) {
			if(r.getWarnings().toString().equals("null")) {
				SQL.createUser(getClient().playerName, getClient().playerPass);
				System.out.println("Created new user " + getClient().playerName);
			} else {
			System.out.println("While loading " + getClient().playerName + ", a sql warning has appeared: " + r.getWarnings().toString());
		}
		}
		int inventoryIndex = r.findColumn("Inventory");
		int bankIndex = r.findColumn("Bank");
		int[][] bank = SQL.getFromString(r.getString(inventoryIndex));
		for(int i = 0; i < bank.length; i++) {
			for(int x = 0; x < bank[i].length; x++) {
				System.out.println("Bank Item: " + bank[i][x]);
			}
		}
	}
	
	public boolean correctInfo() throws SQLException {
		if(getClient() == null) return false;
		if(getClient().playerName == null) return false;
		if(getClient().playerPass == null) return false;
		return SQL.correctInfo(getClient().playerName, getClient().playerPass);
	}
	
	

}
